package ss.pku.meeting.dto;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import ss.pku.meeting.dc.MeetingDataContext;



public class MeetingEvent {
	
	private static SimpleDateFormat sdf_iso=new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");

	private String id;
	private String resourceId;
	private String title;
	private String start;
	private String end;
	private String ownerId;
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getResourceId() {
		return resourceId;
	}
	public void setResourceId(String resourceId) {
		this.resourceId = resourceId;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getStart() {
		return start;
	}
	public void setStart(String start) {
		this.start = start;
	}
	public String getEnd() {
		return end;
	}
	public void setEnd(String end) {
		this.end = end;
	}
	public String getOwnerId() {
		return ownerId;
	}
	public void setOwnerId(String ownerId) {
		this.ownerId = ownerId;
	}
	
	
	public static MeetingDataContext.MeetingEvent toEntity(MeetingEvent dto) throws ParseException {
		MeetingDataContext.MeetingEvent ret=new MeetingDataContext.MeetingEvent();
		ret.setId(dto.getId());
		ret.setResourceId(dto.getResourceId());
		ret.setTitle(dto.getTitle());
		ret.setDeptId(dto.getOwnerId());
		ret.setStart(new Timestamp(sdf_iso.parse(dto.getStart()).getTime()));
		ret.setEnd(new Timestamp(sdf_iso.parse(dto.getEnd()).getTime()));
		
		return ret;
	}
	
	
	public static MeetingEvent fromEntity(MeetingDataContext.MeetingEvent ent) {
		MeetingEvent ret=new MeetingEvent();
		ret.setId(ent.getId());
		ret.setResourceId(ent.getResourceId());
		ret.setTitle(ent.getTitle());
		ret.setOwnerId(ent.getDeptId());
		ret.setStart(sdf_iso.format(ent.getStart()));
		ret.setEnd(sdf_iso.format(ent.getEnd()));
		return ret;
	}

}
